<?php
// $Id$
$config_dir    =  dirname(dirname(dirname(__FILE__))) . "/config/";
$extension_dir =  dirname(dirname(dirname(__FILE__))) . "/lib/";
require_once( $config_dir . "config.controller.inc.php");
require_once( $extension_dir . "phpExcelReader/Excel/reader.php");
/**
 * Controller_Goods 控制器
 */
class Controller_Goods extends Controller_Abstract
{

	function actionIndex()
	{
        // 为 $this->_view 指定的值将会传递数据到视图中
		# $this->_view['text'] = 'Hello!';
	}
    
	function actionUploadGoodsWeb()
	{
        $form = new Form_UploadGoodsWeb(url('goods/uploadgoodsweb'));
        if ($this->_context->isPOST() && $form->validate($_POST))
        {
            try
            {
                $goods_info = new GoodsInfo($form->values());
                $values = $form->values();
                $goods_info->brand_id = $values["brand_id"];
                $goods_info->category_id = $values["category_id"];
                $goods_info->goods_no = $values["goods_no"];
                $goods_info->goods_name = $values["goods_name"];
                $goods_info->keywords = $values["keywords"];
                $goods_info->forum_url = $values["forum_url"];
                $goods_info->description = $values["description"];
                $goods_info->detail = $values["detail"];
                $goods_info->supplier_id = "default_supplier_null";
                $goods_info->goods_bitmap = 0;
                $goods_info->img_urls = $values["imgs"];
                $goods_info->small_img_urls = $values["small_imgs"];
                $goods_info->big_img_urls = $values["big_imgs"];
                
                $goods_property = new GoodsProperty();
                $goods_property->color = $values["color"];
                $goods_property->model = $values["model"];
                $goods_property->size = $values["size"];
                $goods_property->weight = $values["weight"];
                $goods_property->quantity = $values["quantity"];
                $goods_property->unit = $values["unit"];
                
                $time_now = gettimeofday();
                $goods_info->goods_id  = ($time_now["sec"] + "") . $time_now["usec"];
                $goods_property->property_id = $goods_info->goods_id;
                $goods_info->property_id     = $goods_info->goods_id;
                $goods_property->save(99,'create');
                $goods_info->save(99,'create');
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
        else
        {
            echo "Validate Fail.";
        }
	}
	function actionModifyGoodsWeb()
	{
        $form = new Form_UploadGoodsWeb(url('goods/uploadgoodsweb'));
        if ($this->_context->isPOST() && $form->validate($_POST))
        {
            try
            {
                $values = $form->values();

                if (!$values["goods_id"])
                {
                    exit();
                }
                
                $goods_info = GoodsInfo::find("goods_id = ?", $values["goods_id"])->getOne();
                if (!$goods_info->property_id)
                {
                    exit();
                }
                
                $goods_property = GoodsProperty::find("property_id = ?", $goods_info->property_id)->getOne();
                
                $goods_info->brand_id = $values["brand_id"];
                $goods_info->category_id = $values["category_id"];
                $goods_info->goods_no = $values["goods_no"];
                $goods_info->goods_name = $values["goods_name"];
                $goods_info->keywords = $values["keywords"];
                $goods_info->forum_url = $values["forum_url"];
                $goods_info->description = $values["description"];
                $goods_info->detail = $values["detail"];
                $goods_info->supplier_id = "default_supplier_null";
                $goods_info->goods_bitmap = 0;
                $goods_info->img_urls = $values["imgs"];
                $goods_info->small_img_urls = $values["small_imgs"];
                $goods_info->big_img_urls = $values["big_imgs"];
                
                $goods_property->color = $values["color"];
                $goods_property->model = $values["model"];
                $goods_property->size = $values["size"];
                $goods_property->weight = $values["weight"];
                $goods_property->quantity = $values["quantity"];
                $goods_property->unit = $values["unit"];
                
                $goods_property->save();
                $goods_info->save();
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
        else
        {
            echo "Validate Fail.";
        }
	}
    
	function actionModifyGoodsXLS()
	{
        $form = new Form_UploadGoodsXLS(url('goods/uploadgoodsxls'));
        if ($this->_context->isPOST() && $form->validate($_POST))
        {
            try
            {
                if ( $_FILES["goods_file_xls"]["error"] > 0 )
                {
                    echo "error: " . $_FILES["goods_file_xls"]["error"] . "<br />";
                    exit();
                }
                else if ($_FILES["goods_file_xls"]["type"] != "application/vnd.ms-excel")
                {
                    echo $_FILES["goods_file_xls"]["name"] . "is not a excel file.<br />";
                    exit();
                }
                else
                {
                    $time_now = gettimeofday();
                    $time_now_version = $time_now["sec"] . $time_now["usec"];
                    $xls_file = XLS_UPLOAD_GOODS_PATH . $time_now["sec"] . $time_now["usec"] . $_FILES["goods_file_xls"]["name"];
                    if (file_exists($xls_file))
                    {
                        echo $_FILES["goods_file_xls"]["name"] . " already exists. ";
                        exit();
                    }
                    else
                    {
                        move_uploaded_file($_FILES["goods_file_xls"]["tmp_name"], $xls_file);
                        $xls_data = new Spreadsheet_Excel_Reader();
                        $xls_data->setOutputEncoding("UTF-8");
                        $xls_data->read($xls_file);
                        for ($i = 2; $i <= $xls_data->sheets[0]['numRows']; $i++)
                        {
                            $goods_id = $xls_data->sheets[0]['cells'][$i][1];
                            $goods_info = GoodsInfo::find("goods_id = ?", $goods_id)->getOne();
                            if (!$goods_info->property_id)
                            {
                                continue;
                            }
                            $goods_info->goods_name = $xls_data->sheets[0]['cells'][$i][2];
                            $goods_info->goods_no = $xls_data->sheets[0]['cells'][$i][3];
                            $goods_info->brand_id = $xls_data->sheets[0]['cells'][$i][4];
                            $goods_info->category_id = $xls_data->sheets[0]['cells'][$i][5];
                            $goods_info->supplier_id = $xls_data->sheets[0]['cells'][$i][6];
                            $goods_info->keywords = $xls_data->sheets[0]['cells'][$i][7];
                            $goods_info->forum_url = $xls_data->sheets[0]['cells'][$i][8];
                            $goods_info->description = $xls_data->sheets[0]['cells'][$i][15];
                            $goods_info->detail = $xls_data->sheets[0]['cells'][$i][16];
                            $goods_info->big_img_urls = $xls_data->sheets[0]['cells'][$i][17];
                            $goods_info->img_urls = $xls_data->sheets[0]['cells'][$i][18];
                            $goods_info->small_img_urls = $xls_data->sheets[0]['cells'][$i][19];
                            $goods_info->goods_bitmap = 0;
                            
                            $goods_property = GoodsProperty::find("property_id = ?", $goods_info->property_id)->getOne();
                            $goods_property->weight = $xls_data->sheets[0]['cells'][$i][9];
                            $goods_property->quantity = $xls_data->sheets[0]['cells'][$i][10];                            
                            $goods_property->color = $xls_data->sheets[0]['cells'][$i][11];   
                            $goods_property->model = $xls_data->sheets[0]['cells'][$i][12];   
                            $goods_property->size = $xls_data->sheets[0]['cells'][$i][13];   
                            $goods_property->unit = $xls_data->sheets[0]['cells'][$i][14];   
                            $goods_property->save();
                            $goods_info->save();
                        }
                    }
                }
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
        else
        {
            echo "Validate Fail.";
        }
	}
    
	function actionUploadGoodsXLS()
	{
        $form = new Form_UploadGoodsXLS(url('goods/uploadgoodsxls'));
        if ($this->_context->isPOST() && $form->validate($_POST))
        {
            try
            {
                if ( $_FILES["goods_file_xls"]["error"] > 0 )
                {
                    echo "error: " . $_FILES["goods_file_xls"]["error"] . "<br />";
                    exit();
                }
                else if ($_FILES["goods_file_xls"]["type"] != "application/vnd.ms-excel")
                {
                    echo $_FILES["goods_file_xls"]["name"] . "is not a excel file.<br />";
                    exit();
                }
                else
                {
                    $time_now = gettimeofday();
                    $time_now_version = $time_now["sec"] . $time_now["usec"];
                    $xls_file = XLS_UPLOAD_GOODS_PATH . $time_now["sec"] . $time_now["usec"] . $_FILES["goods_file_xls"]["name"];
                    if (file_exists($xls_file))
                    {
                        echo $_FILES["goods_file_xls"]["name"] . " already exists. ";
                        exit();
                    }
                    else
                    {
                        move_uploaded_file($_FILES["goods_file_xls"]["tmp_name"], $xls_file);
                        $xls_data = new Spreadsheet_Excel_Reader();
                        $xls_data->setOutputEncoding("UTF-8");
                        $xls_data->read($xls_file);
                        $goods_info = new GoodsInfo();
                        for ($i = 2; $i <= $xls_data->sheets[0]['numRows']; $i++)
                        {
                            $goods_info->goods_name = $xls_data->sheets[0]['cells'][$i][2];
                            $goods_info->goods_no = $xls_data->sheets[0]['cells'][$i][3];
                            $goods_info->brand_id = $xls_data->sheets[0]['cells'][$i][4];
                            $goods_info->category_id = $xls_data->sheets[0]['cells'][$i][5];
                            $goods_info->supplier_id = $xls_data->sheets[0]['cells'][$i][6];
                            $goods_info->keywords = $xls_data->sheets[0]['cells'][$i][7];
                            $goods_info->forum_url = $xls_data->sheets[0]['cells'][$i][8];
                            $goods_info->description = $xls_data->sheets[0]['cells'][$i][15];
                            $goods_info->detail = $xls_data->sheets[0]['cells'][$i][16];
                            $goods_info->big_img_urls = $xls_data->sheets[0]['cells'][$i][17];
                            $goods_info->img_urls = $xls_data->sheets[0]['cells'][$i][18];
                            $goods_info->small_img_urls = $xls_data->sheets[0]['cells'][$i][19];
                            $goods_info->goods_bitmap = 0;
                            $goods_info->goods_id = $time_now_version . "-" . $i;  
                            
                            $goods_property = new GoodsProperty();
                            $goods_property->weight = $xls_data->sheets[0]['cells'][$i][9];
                            $goods_property->quantity = $xls_data->sheets[0]['cells'][$i][10];                            
                            $goods_property->color = $xls_data->sheets[0]['cells'][$i][11];   
                            $goods_property->model = $xls_data->sheets[0]['cells'][$i][12];   
                            $goods_property->size = $xls_data->sheets[0]['cells'][$i][13];   
                            $goods_property->unit = $xls_data->sheets[0]['cells'][$i][14];   
                            $goods_property->property_id = $goods_info->goods_id;
                            $goods_info->property_id     = $goods_info->goods_id;
                            $goods_property->save(99,'create');
                            $goods_info->save(99,'create');
                        }
                    }
                }
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
        else
        {
            echo "Validate Fail.";
        }
	}
    
    function actionUploadOnshelfGoodsWeb()
    {
        $form = new Form_UploadGoodsOnshelfWeb(url('goods/uploadgoodsonshelfweb'));
        if ($this->_context->isPOST() && $form->validate($_POST))
        {
            try
            {
                $onshelf_goods = new GoodsOnshelf($form->values());
                $values = $form->values();
                $time_now = gettimeofday();
                $time_now_version = $time_now["sec"] . $time_now["usec"];
                
                $onshelf_goods->goods_id = $values["goods_id"];
                $onshelf_goods->stock = $values["stock"];
                $onshelf_goods->min_stock = $values["min_stock"];
                $onshelf_goods->market_price = $values["market_price"];
                $onshelf_goods->mall_price = $values["mall_price"];
                $onshelf_goods->vip_price = $values["vip_price"];
                $onshelf_goods->coupon_type = $values["coupon_type"];
                $onshelf_goods->discount_card_type = $values["discount_card_type"];
                $onshelf_goods->cross_sell_product_ids = $values["cross_sell_product_ids"];
                $onshelf_goods->bundle_product_ids = $values["bundle_product_ids"];
                $onshelf_goods->paytool_ids = $values["paytool_ids"];
                $onshelf_goods->gift_ids = $values["gift_ids"];
                $onshelf_goods->point = $values["point"];
                $onshelf_goods->exp = $values["exp"];
                $onshelf_goods->vip_exp = $values["vip_exp"];
                $onshelf_goods->goods_onshelf_bitmap = 0;
                $onshelf_goods->goods_onshelf_id = $time_now_version;  
                            
                $onshelf_goods->save(99,'create');
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
        else
        {
            echo "Validate Fail.";
        }
    }
    
    function actionModifyOnshelfGoodsWeb()
    {
        $form = new Form_UploadGoodsOnshelfWeb(url('goods/uploadgoodsonshelfweb'));
        if ($this->_context->isPOST() && $form->validate($_POST))
        {
            try
            {
                $values = $form->values();
                $onshelf_goods = GoodsOnshelf::find("goods_onshelf_id = ?", $values["goods_onshelf_id"])->getOne();
                if (!$onshelf_goods->goods_id)
                {
                    exit();
                }
                
                $onshelf_goods->stock = $values["stock"];
                $onshelf_goods->min_stock = $values["min_stock"];
                $onshelf_goods->market_price = $values["market_price"];
                $onshelf_goods->mall_price = $values["mall_price"];
                $onshelf_goods->vip_price = $values["vip_price"];
                $onshelf_goods->coupon_type = $values["coupon_type"];
                $onshelf_goods->discount_card_type = $values["discount_card_type"];
                $onshelf_goods->cross_sell_product_ids = $values["cross_sell_product_ids"];
                $onshelf_goods->bundle_product_ids = $values["bundle_product_ids"];
                $onshelf_goods->paytool_ids = $values["paytool_ids"];
                $onshelf_goods->gift_ids = $values["gift_ids"];
                $onshelf_goods->point = $values["point"];
                $onshelf_goods->exp = $values["exp"];
                $onshelf_goods->vip_exp = $values["vip_exp"];
                $onshelf_goods->goods_onshelf_bitmap = 0;
                            
                $onshelf_goods->save();
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
        else
        {
            echo "Validate Fail.";
        }
    }
    
	function actionOnshelfGoodsXLS()
	{
        $form = new Form_UploadGoodsXLS(url('goods/uploadgoodsxls'));
        if ($this->_context->isPOST() && $form->validate($_POST))
        {
            try
            {
                if ( $_FILES["goods_file_xls"]["error"] > 0 )
                {
                    echo "error: " . $_FILES["goods_file_xls"]["error"] . "<br />";
                    exit();
                }
                else if ($_FILES["goods_file_xls"]["type"] != "application/vnd.ms-excel")
                {
                    echo $_FILES["goods_file_xls"]["name"] . "is not a excel file.<br />";
                    exit();
                }
                else
                {
                    $time_now = gettimeofday();
                    $time_now_version = $time_now["sec"] . $time_now["usec"];
                    $xls_file = XLS_ONSHELF_GOODS_PATH . $time_now["sec"] . $time_now["usec"] . $_FILES["goods_file_xls"]["name"];
                    if (file_exists($xls_file))
                    {
                        echo $_FILES["goods_file_xls"]["name"] . " already exists. ";
                        exit();
                    }
                    else
                    {
                        move_uploaded_file($_FILES["goods_file_xls"]["tmp_name"], $xls_file);
                        $xls_data = new Spreadsheet_Excel_Reader();
                        $xls_data->setOutputEncoding("UTF-8");
                        $xls_data->read($xls_file);
                        $onshelf_goods = new GoodsOnshelf();
                        for ($i = 2; $i <= $xls_data->sheets[0]['numRows']; $i++)
                        {
                            $onshelf_goods->goods_id = $xls_data->sheets[0]['cells'][$i][2];
                            $onshelf_goods->stock = $xls_data->sheets[0]['cells'][$i][3];
                            $onshelf_goods->min_stock = $xls_data->sheets[0]['cells'][$i][4];
                            $onshelf_goods->market_price = $xls_data->sheets[0]['cells'][$i][5];
                            $onshelf_goods->mall_price = $xls_data->sheets[0]['cells'][$i][6];
                            $onshelf_goods->vip_price = $xls_data->sheets[0]['cells'][$i][7];
                            $onshelf_goods->coupon_type = $xls_data->sheets[0]['cells'][$i][8];
                            $onshelf_goods->discount_card_type = $xls_data->sheets[0]['cells'][$i][9];
                            $onshelf_goods->cross_sell_product_ids = $xls_data->sheets[0]['cells'][$i][10];
                            $onshelf_goods->bundle_product_ids = $xls_data->sheets[0]['cells'][$i][11];
                            $onshelf_goods->paytool_ids = $xls_data->sheets[0]['cells'][$i][12];
                            $onshelf_goods->gift_ids = $xls_data->sheets[0]['cells'][$i][13];
                            $onshelf_goods->point = $xls_data->sheets[0]['cells'][$i][14];
                            $onshelf_goods->exp = $xls_data->sheets[0]['cells'][$i][15];
                            $onshelf_goods->vip_exp = $xls_data->sheets[0]['cells'][$i][16];
                            $onshelf_goods->goods_onshelf_bitmap = 0;
                            $onshelf_goods->goods_onshelf_id = $time_now_version . "-" . $i;  
                            
                            $onshelf_goods->save(99,'create');
                        }
                    }
                }
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
        else
        {
            echo "Validate Fail.";
        }
	}
    
	function actionModifyOnshelfGoodsXLS()
	{
        $form = new Form_UploadGoodsXLS(url('goods/uploadgoodsxls'));
        if ($this->_context->isPOST() && $form->validate($_POST))
        {
            try
            {
                if ( $_FILES["goods_file_xls"]["error"] > 0 )
                {
                    echo "error: " . $_FILES["goods_file_xls"]["error"] . "<br />";
                    exit();
                }
                else if ($_FILES["goods_file_xls"]["type"] != "application/vnd.ms-excel")
                {
                    echo $_FILES["goods_file_xls"]["name"] . "is not a excel file.<br />";
                    exit();
                }
                else
                {
                    $time_now = gettimeofday();
                    $time_now_version = $time_now["sec"] . $time_now["usec"];
                    $xls_file = XLS_ONSHELF_GOODS_PATH . $time_now["sec"] . $time_now["usec"] . $_FILES["goods_file_xls"]["name"];
                    if (file_exists($xls_file))
                    {
                        echo $_FILES["goods_file_xls"]["name"] . " already exists. ";
                        exit();
                    }
                    else
                    {
                        move_uploaded_file($_FILES["goods_file_xls"]["tmp_name"], $xls_file);
                        $xls_data = new Spreadsheet_Excel_Reader();
                        $xls_data->setOutputEncoding("UTF-8");
                        $xls_data->read($xls_file);
                        
                        for ($i = 2; $i <= $xls_data->sheets[0]['numRows']; $i++)
                        {
                            $onshelf_goods = GoodsOnshelf::find("goods_onshelf_id = ?", $xls_data->sheets[0]['cells'][$i][1])->getOne();
                            if (!$onshelf_goods->goods_id)
                            {
                                continue;
                            }
                            //$onshelf_goods->goods_id = $xls_data->sheets[0]['cells'][$i][2];
                            $onshelf_goods->stock = $xls_data->sheets[0]['cells'][$i][3];
                            $onshelf_goods->min_stock = $xls_data->sheets[0]['cells'][$i][4];
                            $onshelf_goods->market_price = $xls_data->sheets[0]['cells'][$i][5];
                            $onshelf_goods->mall_price = $xls_data->sheets[0]['cells'][$i][6];
                            $onshelf_goods->vip_price = $xls_data->sheets[0]['cells'][$i][7];
                            $onshelf_goods->coupon_type = $xls_data->sheets[0]['cells'][$i][8];
                            $onshelf_goods->discount_card_type = $xls_data->sheets[0]['cells'][$i][9];
                            $onshelf_goods->cross_sell_product_ids = $xls_data->sheets[0]['cells'][$i][10];
                            $onshelf_goods->bundle_product_ids = $xls_data->sheets[0]['cells'][$i][11];
                            $onshelf_goods->paytool_ids = $xls_data->sheets[0]['cells'][$i][12];
                            $onshelf_goods->gift_ids = $xls_data->sheets[0]['cells'][$i][13];
                            $onshelf_goods->point = $xls_data->sheets[0]['cells'][$i][14];
                            $onshelf_goods->exp = $xls_data->sheets[0]['cells'][$i][15];
                            $onshelf_goods->vip_exp = $xls_data->sheets[0]['cells'][$i][16];
                            $onshelf_goods->goods_onshelf_bitmap = 0;
                            
                            $onshelf_goods->save();
                        }
                    }
                }
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
        else
        {
            echo "Validate Fail.";
        }
	}
    
    function getGoodsFromExcel($xls_file)
    {
        if (!file_exists($xls_file))
        {
            echo $xls_file . "is not exist.<br />";
            return null;
        }
        $goods = Array();
        $xls_data = new Spreadsheet_Excel_Reader();
        $xls_data->setOutputEncoding("UTF-8");
        $xls_data->read($xls_file);
        for ($i = 2; $i <= $xls_data->sheets[0]['numRows']; $i++)
        {
            for ($j = 2; $j <= $xls_data->sheets[0]['numCols']; $j++) 
            {
                echo "\"".$xls_data->sheets[0]['cells'][$i][$j]."\",";
            }
            echo "\n";
        }
    }
    
    function actionGenerateGoodsOnshelfJSONXLS()
    {
        $form = new Form_GenerateGoodsOnshelfJSON(url('category/generatecategorygoodsjson'));
        if ( $this->_context->isPOST() && $form->validate($_POST) )
        {
            try
            {
                if ( $_FILES["goods_file_xls"]["error"] > 0 )
                {
                    echo "error: " . $_FILES["goods_file_xls"]["error"] . "<br />";
                    exit();
                }
                else if ($_FILES["goods_file_xls"]["type"] != "application/vnd.ms-excel")
                {
                    echo $_FILES["goods_file_xls"]["name"] . "is not a excel file.<br />";
                    exit();
                }
                else
                {
                    $time_now = gettimeofday();
                    $time_now_version = $time_now["sec"] . $time_now["usec"];
                    $xls_file = XLS_UPLOAD_GOODS_PATH . $time_now["sec"] . $time_now["usec"] . $_FILES["goods_file_xls"]["name"];
                    if (file_exists($xls_file))
                    {
                        echo $_FILES["goods_file_xls"]["name"] . " already exists. ";
                        exit();
                    }
                    else
                    {
                        move_uploaded_file($_FILES["goods_file_xls"]["tmp_name"], $xls_file);
                        $xls_data = new Spreadsheet_Excel_Reader();
                        $xls_data->setOutputEncoding("UTF-8");
                        $xls_data->read($xls_file);
                        $json_goods = new Array();
                        for ($i = 2; $i <= $xls_data->sheets[0]['numRows']; $i++)
                        {
                            $goods_onshelf_id = $xls_data->sheets[0]['cells'][$i][1];
                            $goods_onshelf = GoodsOnshelf::find("goods_onshelf_id = ?", $goods_onshelf_id)->getOne();
                            if (!$goods_onshelf->goods_id)
                            {
                                exit();
                            }
                            $goods_info = GoodsInfo::find("goods_id = ?", $goods_onshelf->goods_id)->getOne();
                            if (!$goods_info->property_id)
                            {
                                exit();
                            }
                            $goods_property = GoodsProperty::find("property_id = ?", $goods_info->property_id)->getOne();
                            
                            $json_goods["goods_onshelf_id"] = $goods_onshelf_id;
                            $json_goods["goods_name"] = $goods_info->goods_name;
                            $json_goods["goods_no"] = $goods_info->goods_name;
                            $json_goods["brand_name"] = $brand->brand_name;
                            $json_goods["detail"] = $goods_info->detail;
                            $json_goods["img_urls"] = $goods_info->img_urls;
                            $json_goods["weight"] = $goods_property->weight;
                            $json_goods["quantity"] = $goods_property->quantity;
                            $json_goods["unit"] = $goods_property->unit;
                            $json_goods["color"] = $goods_property->color;
                            $json_goods["model"] = $goods_property->model;
                            $json_goods["size"] = $goods_property->size;
                            $json_goods["stock"] = $goods_onshelf->stock;
                            $json_goods["mall_price"] = $goods_onshelf->mall_price;
                            $json_goods["vip_price"] = $goods_onshelf->vip_price;
                            $brand = Brand::find("brand_id = ?", $goods_info->brand_id)->getOne();
                            $json_string = "fillAct(" . json_encode($json_goods) . ", 'goods/goods_onshelf_json');";
                            $json_path = JSON_GOODS_ONSHELF_PATH . $brand->category_id . "/" . $goods_info->brand_id . "/";
                            if ($json_path != '.' && $json_path != '..' && !is_dir($json_path))
                            {
                                passthru("mkdir -p $json_path >/dev/null");
                            }
                            
                            $json_name = $json_path . $goods_onshelf_id . ".js";
                            $fh = fopen($json_name, "w");
                            if ( $fh == null )
                            {
                                //echo $callback .  "(" . $json . ")";
                                exit();
                            }
                            fwrite($fh, $json_string);
                            fclose($fh);
                        }
                        $json = new Array();
                        $json["goods_recommended"] = $json_goods;
                        $json_string = "fillAct(" . json_encode($json) . ", 'brand/brand_goods_recommended');";
                        $json_path = JSON_BRAND_RECOMMENDED_PATH . $brand->category_id . "/" . $goods_info->brand_id . "/";
                        if ($json_path != '.' && $json_path != '..' && !is_dir($json_path))
                        {
                            passthru("mkdir -p $json_path >/dev/null");
                        }
                        
                        $json_name = $json_path. $goods_info->brand_id . ".js";
                        $fh = fopen($json_name, "w");
                        if ( $fh == null )
                        {
                            //echo $callback .  "(" . $json . ")";
                            exit();
                        }
                        fwrite($fh, $json_string);
                        fclose($fh);
                    }
                }
            }
            catch (Exception $ex)
            {
                print_r($ex);
                exit();
            }
        }
    }
}


